package com.space.school.service.impl;

import com.space.school.dao.DetailDao;
import com.space.school.dao.InfoDao;
import com.space.school.dao.impl.DetailDaoImpl;
import com.space.school.dao.impl.InfoDaoImpl;
import com.space.school.domain.Detail;
import com.space.school.domain.Master;
import com.space.school.service.DetailService;

import java.util.List;

public class DetailServiceImpl implements DetailService {
    DetailDao detailDao =new DetailDaoImpl();
    InfoDao infoDao =new InfoDaoImpl();
    @Override
    public void del(String order_id) {
        detailDao.del(order_id);
    }

    @Override
    public boolean insert(Detail detail) {
//        累计点餐数量
        int now= detail.getProduct_num()+detailDao.find_product_num(detail);
//        库存数量
        int stock=infoDao.findStock(Integer.parseInt(detail.getProduct_id()));
        if(now<=stock){
            detailDao.add(detail);
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<Master> find_sum(Long order_id) {
        return detailDao.find_sum(order_id);
    }


}
